// pages/search/search.js
const service = require('../../utils/service.js')
const api = require('../../utils/util.js')
Page({
  data: {
    activityList: [],
    tabIndex: -1,
    page: 1,
    nameShow: true,
    have_data: true
  },
  init: function() {
    let shop_code = wx.getStorageSync('shopInfo').shop_code,
      self = this,
      shopData = wx.getStorageSync('shop_data_shop');
    api.ajax(service.url('getCouponActiveList'), {
      unionid: shopData.shop_unionid,
      token: shopData.token,
      token_key: shopData.token_key,
      shop_code: shop_code,
      is_active: '',
      page: this.data.page,
    }, function(res) {
      // var shopCode = res.data.shop_code; // 商店id
      if (res.code == 0) {
        self.setData({
          tabIndex: res.data == '' ? 1 : 0,
          activityList: res.data
        });
      } else {
        api.toast(res.message || '没有数据了！')
      }
      console.log("activityList：" + JSON.stringify(res))
    });
  },
  next: function() {
    this.setData({
      nameShow: false
    });
  },
  //--删除店铺活动
  ShopActivityDel: function(et) {
    let shop_code = wx.getStorageSync('shopInfo').shop_code,
      self = this,
      coupon_id = et.currentTarget.dataset.couponid,
      shopData = wx.getStorageSync('shop_data_shop');
    wx.showModal({
      title: "温馨提示",
      content: '请确认是否删除该店铺活动',
      success: function(res) {
        console.log(res);
        if (res.confirm) {
          api.ajax(service.url('delCouponActive'), {
            unionid: shopData.shop_unionid,
            token: shopData.token,
            token_key: shopData.token_key,
            shop_code: shop_code,
            coupon_id: coupon_id,
          }, function(res) {
            console.log("activityDel：" + JSON.stringify(res));
            if (res.code == 0) {
              api.toast('已删除店铺活动！');
              self.init();
            } else {
              api.toast(res.message || "数据出现错误！");
            }
          });
        } else {
          api.toast("取消删除！");
        }
      },
      fail: function() {
        alert("微信API弹窗调用失败！");
      }
    });
  },
  openShopActivityAdd: function() {
    wx.navigateTo({
      url: '../shop_activity/add/add'
    });
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    //this.init();
  },
  /**
   * 页面显示/切入前台时触发
   */
  onShow: function() {
    this.init();
  }
})